package com.anro.util

import android.app.Activity
import java.util.*
import java.util.concurrent.CopyOnWriteArrayList
import kotlin.collections.ArrayList

class ActivityCollector{

    companion object{
        val instance: ActivityCollector by lazy { ActivityCollector() }
        val activitys: CopyOnWriteArrayList<Activity> = CopyOnWriteArrayList()
    }

    /**
     * 向List中添加一个活动
     *
     * @param activity 活动
     */
    fun addActivity(activity: Activity) {
        activitys.add(activity)
    }

    /**
     * 从List中移除活动
     *
     * @param activity 活动
     */
    fun removeActivity(activity: Activity) {
        activitys.remove(activity)
    }

    /**
     * 将List中存储的活动全部销毁掉
     */

    fun finishAll() {
        for (activity in activitys) {
            activity.finish()
        }
        activitys.clear()
    }


    fun currentActivity():Activity{
        return activitys[activitys.size-1];
    }


}







